/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gui;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;

import com.beans.Projets;
import com.beans.Users;
import com.metier.CongesMetier;
import com.metier.NombreJourCongesMetier;
import com.metier.ProjetMetier;
import com.metier.UsersMetier;
import com.tools.BICButtonDegrade;

/**
 * 
 * @author Sarr_moussa
 */
public class FenMain extends JFrame {

	private JButton buttonAceuil;
	private JButton buttonGestionProjets;
	private JButton buttonMonCompte;
	private JButton buttonValiderModifierMonCompte;
	private JButton buttonQuitter,boutonDeconnecter;
	private JButton boutonUtilisateur;
	private JButton boutonConge, boutonProspect, boutonCra;
	private JButton boutonAo;
	private JButton boutonEntrees;
	private JButton boutonSorties;
	private JButton boutonMesProjets;
	private JButton boutonRetourMesProjets;
	private JButton boutonRetourMesConges;
	private JButton boutonRetourAjouterMesConges;
	private JButton boutonRetourAddConges;
	private JButton boutonAjouterMesConges;
	private JButton boutonValiderAddConges;
	private JButton boutonAnnulerAddConges;
	private Users userConnecter;
	private UsersMetier userMetier;
	private JLabel labelProfil;
private long  usrrecup;
	private JLabel jLabel1;
	private JLabel jLabel2;
	private String logMonCompte;
	private String logrecuperer, passwordrecuperer;
	JPanel panBoutonHaut= new JPanel();
	JPanel panBoutonHautMesConges= new JPanel();
	static String pass=""; static String newPass="";
	JButton boutonRechercher= new JButton();
	JPanel panelRechercheProjet= new JPanel();

	public String getLogMonCompte() {
		return logMonCompte;
	}

	public void setLogMonCompte(String logMonCompte) {
		this.logMonCompte = logMonCompte;
	}

	public JButton getButtonGestionProjets() {
		return buttonGestionProjets;
	}

	public long getUsrrecup() {
		return usrrecup;
	}

	public void setUsrrecup(long usrrecup) {
		this.usrrecup = usrrecup;
	}

	public void setButtonGestionProjets(JButton buttonGestionProjets) {
		this.buttonGestionProjets = buttonGestionProjets;
	}

	public JButton getjButton3() {
		return boutonUtilisateur;
	}

	public void setjButton3(JButton jButton3) {
		this.boutonUtilisateur = jButton3;
	}

	public JLabel getLabelConnecter() {
		return labelConnecter;
	}

	public void setLabelConnecter(JLabel labelConnecter) {
	}

	public String getLogrecuperer() {
		return logrecuperer;
	}

	public void setLogrecuperer(String logrecuperer) {
		this.logrecuperer = logrecuperer;
	}

	public String getPasswordrecuperer() {
		return passwordrecuperer;
	}

	public void setPasswordrecuperer(String passwordrecuperer) {
		this.passwordrecuperer = passwordrecuperer;
	}

	private JLabel labelBienVenue;
	private JLabel jLabel4;
	private JLabel labelAcceuil, labelConnecter;

	public JPanel getPanCentreFenMain() {
		return panCentreFenMain;
	}

	public void setPanCentreFenMain(JPanel panCentreFenMain) {
		this.panCentreFenMain = panCentreFenMain;
	}

	private JPanel jPanel1;
	private JPanel panBasFenMain;
	private JPanel panCentreFenMain;
	private JPanel panGaucheFenMain;
	private JPanel panHautFenMain, panHautFenMainGauche, panHautFenMainCentre,
			panHautFenMainDroite;
	com.gui.mon_Compte monCompte;
	private JButton boutonMesConges;
	PanelAddConges panAddConges;
	PanelConges panConges;
	JPanel panelBoutonMesProjets= new JPanel();
	PanelMesProjets panMesProjets;
	JPanel panelBoutonsAddConge= new JPanel();
	PanelAcceilProjets fenGestionConsultant;
	//private JButton boutonRetourMesProjets= new JButton("Retour");

	public FenMain() {
		userConnecter = new Users();
		userMetier = new UsersMetier();
		panConges= new PanelConges();
		initComponents();
		setTitle("Fenetre de Bienvenue");

		setLocationRelativeTo(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setResizable(false);
		setSize(1250, 700);
		go();
		defiler();
	}

	private void initComponents() {
		Container contenu = getContentPane();
		contenu.setLayout(new BorderLayout());

		panMesProjets= new PanelMesProjets();
		userMetier = new UsersMetier();
		panHautFenMain = new JPanel();
		panBasFenMain = new JPanel();
		panGaucheFenMain = new JPanel();
		panHautFenMainCentre = new JPanel();
		panHautFenMainCentre.setLayout(new GridLayout(1, 1));
		panHautFenMainGauche = new JPanel();
		panCentreFenMain = new JPanel();
		panHautFenMainDroite=new JPanel();
		boutonValiderAddConges= new JButton("valider");
		boutonAnnulerAddConges= new JButton("annuler");
	    panCentreFenMain.setSize(1050, 550);
	    panAddConges= new PanelAddConges(boutonValiderAddConges, boutonAnnulerAddConges);
	    boutonAjouterMesConges= new JButton("Ajouter");
	    boutonMesConges= new JButton("MES CONGES");
	    boutonMesProjets= new JButton("MES PROJETS");
	    buttonValiderModifierMonCompte= new JButton("valider");
	    monCompte = new mon_Compte(boutonMesProjets,boutonMesConges,buttonValiderModifierMonCompte);
	    boutonRetourMesConges= new JButton("Retour");
	    boutonRetourAjouterMesConges= new JButton("Retour");
	    boutonRetourMesProjets= new JButton("Retour");
	    boutonRetourAddConges= new JButton("Retour");
	    // Définition du panel panelBoutonsAddConge
	    panelBoutonsAddConge.setLayout(new GridLayout(1,10));
	    panelBoutonsAddConge.add(boutonRetourAddConges);
		for (int i=0; i<9; i++)
			panelBoutonsAddConge.add(new JLabel("  "));
                            
		panBoutonHautMesConges.setLayout(new GridLayout(1,10));
		panBoutonHautMesConges.add(boutonRetourMesConges);
		panBoutonHautMesConges.add(boutonAjouterMesConges);
		for (int j=0; j<8; j++)
			panBoutonHautMesConges.add(new JLabel("  "));
		
	    panBoutonHaut.setLayout(new GridLayout(1,10,5,5));
		panBoutonHaut.add(boutonRetourAjouterMesConges);
		for (int i=0; i<9; i++)
			panBoutonHaut.add(new JLabel("  "));
		
<<<<<<< .mine
	   fenGestionConsultant = new PanelAcceilProjets(boutonRechercher);
=======
	    fenGestionConsultant = new PanelAcceilProjets(boutonRechercher);
>>>>>>> .r69
	   
	    boutonMesProjets.addActionListener(new ActionListener() {
		
		public void actionPerformed(ActionEvent arg0) {
			// TODO Auto-generated method stub
			userConnecter = userMetier.findUserByLogin(getLogrecuperer());
			//structuration du panel centre ;
			panMesProjets.removeAll();
			panelBoutonMesProjets.removeAll();
			panelBoutonMesProjets.setSize(1050, 50);
			panelBoutonMesProjets.setLayout(new GridLayout(1,10));
			panelBoutonMesProjets.add(boutonRetourMesProjets);
			for (int k=0; k<9; k++)
				panelBoutonMesProjets.add(new JLabel("  "));
            
			panMesProjets.setUsrId(userConnecter.getUsrId());
			panMesProjets.initComponents();
			monCompte.remove(monCompte.getPanelBoutons());
			monCompte.remove(monCompte.getPanelBas());
			monCompte.add(panelBoutonMesProjets, BorderLayout.CENTER);
			monCompte.add(panMesProjets,BorderLayout.SOUTH);
			monCompte.revalidate();
			getContentPane().revalidate();
	   	}
	});
	   
	  // boutonRetourMesProjets= new JButton("Retour");
	   boutonRetourMesProjets.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				monCompte.remove(panMesProjets);
				monCompte.remove(panelBoutonMesProjets);
				monCompte.add(monCompte.getPanelBoutons(), BorderLayout.CENTER);
				monCompte.add(monCompte.getPanelBas(), BorderLayout.SOUTH);
				getContentPane().revalidate();
			}
		});

		boutonRetourMesProjets = new JButton("Retour");
		boutonRetourMesProjets.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub

				monCompte = new mon_Compte(boutonMesProjets, boutonMesConges,buttonValiderModifierMonCompte);
				
				monCompte.getLabelProfil().setIcon(
						new javax.swing.ImageIcon(
								"src/main/java/com/photos/user/"
										+ getLogrecuperer() + ".jpg"));
				userConnecter = userMetier.findUserByLogin(getLogrecuperer());
				String nom = userConnecter.getUsrNom();
				String prenom = userConnecter.getUsrPrenom();
				String profil = userConnecter.getUsrProfil();
				String login = userConnecter.getUsrLogin();
				String passAncien = userConnecter.getUsrPasswd();
				// String passNouveau = userConnecter.getUsrPasswd();
				String email = userConnecter.getUsrEmail();
				String phone = userConnecter.getUsrPhone();
				String adresse = userConnecter.getUsrAdresse();
				// on remplit les champs dans monCompte

				monCompte.getTextPrenom().setText(prenom);
				monCompte.getTextNom().setText(nom);
				monCompte.getTextAdresse().setText(adresse);
				monCompte.getTextEmail().setText(email);
				monCompte.getTextLogin().setText(login);
				monCompte.getTextPhone().setText(phone);
				monCompte.getTextProfil().setText(profil);

				monCompte.getTextNom().setEditable(false);
				monCompte.getTextPrenom().setEditable(false);
				monCompte.getTextProfil().setEditable(false);
				monCompte.getTextAdresse().setEditable(false);
				monCompte.getTextLogin().setEditable(false);
				monCompte.getTextEmail().setEditable(false);
				monCompte.getTextPhone().setEditable(false);
				monCompte.getTextAncienPassword().setVisible(false);
				monCompte.getTextNewPassword().setVisible(false);
				monCompte.getjLabel9().setVisible(false);
				monCompte.getjLabel8().setVisible(false);
				monCompte.getTextAncienPassword().setVisible(false);
				buttonValiderModifierMonCompte.setVisible(false);
				monCompte.getBoutonAnnuler().setVisible(false);
				panCentreFenMain.removeAll();
				panCentreFenMain.add(monCompte, BorderLayout.CENTER);
				getContentPane().revalidate();
			}
		});

		boutonMesConges.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				panConges.removeAll();
				panBoutonHautMesConges.removeAll();
				monCompte.remove(monCompte.getPanelBas());
				monCompte.remove(monCompte.getPanelBoutons());
				
				panBoutonHautMesConges.setSize(1050, 50);
				panBoutonHautMesConges.setLayout(new GridLayout(1,10));
				// Chargement du panel panBoutonHaut
				panBoutonHautMesConges.add(boutonRetourMesConges);
				panBoutonHautMesConges.add(boutonAjouterMesConges);
				for (int i=0; i<8; i++)
					panBoutonHautMesConges.add(new JLabel("  "));
				userConnecter = userMetier.findUserByLogin(getLogrecuperer());
				panConges.setUsrId(userConnecter.getUsrId());
				// Appel de la méthode initComponents pour charger le panel panConges
				panConges.initComponents();
				monCompte.add(panConges, BorderLayout.SOUTH);
				monCompte.add(panBoutonHautMesConges, BorderLayout.CENTER);
				monCompte.revalidate();
				getContentPane().revalidate();
			}
		});
	  
	   boutonRetourMesConges.addActionListener(new ActionListener() {
	   		
	   	   	public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
	   	   	monCompte = new mon_Compte(boutonMesProjets, boutonMesConges,buttonValiderModifierMonCompte);
			
			monCompte.getLabelProfil().setIcon(
					new javax.swing.ImageIcon(
							"src/main/java/com/photos/user/"
									+ getLogrecuperer() + ".jpg"));
				userConnecter = userMetier.findUserByLogin(getLogrecuperer());
				String nom = userConnecter.getUsrNom();
				String prenom = userConnecter.getUsrPrenom();
				String profil = userConnecter.getUsrProfil();
				String login = userConnecter.getUsrLogin();
				String passAncien = userConnecter.getUsrPasswd();
				// String passNouveau = userConnecter.getUsrPasswd();
				String email = userConnecter.getUsrEmail();
				String phone = userConnecter.getUsrPhone();
				String adresse = userConnecter.getUsrAdresse();
				// on remplit les champs dans monCompte

				monCompte.getTextPrenom().setText(prenom);
				monCompte.getTextNom().setText(nom);
				monCompte.getTextAdresse().setText(adresse);
				monCompte.getTextEmail().setText(email);
				monCompte.getTextLogin().setText(login);
				monCompte.getTextPhone().setText(phone);
				monCompte.getTextProfil().setText(profil);

				monCompte.getTextNom().setEditable(false);
				monCompte.getTextPrenom().setEditable(false);
				monCompte.getTextProfil().setEditable(false);
				monCompte.getTextAdresse().setEditable(false);
				monCompte.getTextLogin().setEditable(false);
				monCompte.getTextEmail().setEditable(false);
				monCompte.getTextPhone().setEditable(false);
				monCompte.getTextAncienPassword().setVisible(false);
				monCompte.getTextNewPassword().setVisible(false);
				monCompte.getjLabel9().setVisible(false);
				monCompte.getjLabel8().setVisible(false);
				monCompte.getTextAncienPassword().setVisible(false);
				buttonValiderModifierMonCompte.setVisible(false);
				monCompte.getBoutonAnnuler().setVisible(false);
				panCentreFenMain.removeAll();
				panCentreFenMain.add(monCompte, BorderLayout.CENTER);
				getContentPane().revalidate();
			}
		});
	   
	    boutonAjouterMesConges.addActionListener(new ActionListener() {
		
		public void actionPerformed(ActionEvent arg0) {
			// TODO Auto-generated method stub
			monCompte.removeAll();
			/*monCompte.removeAll(panBoutonHautMesConges);
			monCompte.remove(panConges);*/
			panelBoutonsAddConge.setVisible(true);
			panAddConges.setVisible(true);
			// On vide et recharge de nouveau le panel panBoutonHautMesConges
            panelBoutonsAddConge.removeAll();
            panelBoutonsAddConge.setSize(1050, 50);
			panelBoutonsAddConge.setLayout(new GridLayout(1,10));
			panelBoutonsAddConge.add(boutonRetourAjouterMesConges);
			for (int j=0; j<9; j++)
				panelBoutonsAddConge.add(new JLabel("  "));
			// On vide et recharge de nouveau le panel panAddConges
			panAddConges.removeAll();
			panAddConges.initComponents(boutonValiderAddConges, boutonAnnulerAddConges);
			monCompte.add(panelBoutonsAddConge, BorderLayout.CENTER);
			monCompte.add(panAddConges,BorderLayout.SOUTH);
			monCompte.add(monCompte.getPanelHaut(), BorderLayout.NORTH);
			monCompte.revalidate();
			getContentPane().revalidate();
		}
	});
	   
	   boutonRetourAjouterMesConges.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				panelBoutonsAddConge.setVisible(false);
				panAddConges.setVisible(false);
				monCompte.remove(panelBoutonsAddConge);
				monCompte.remove(panAddConges);
				
				panBoutonHautMesConges.removeAll();
				panBoutonHautMesConges.setLayout(new GridLayout(1,10));
				panBoutonHautMesConges.add(boutonRetourMesConges);
				panBoutonHautMesConges.add(boutonAjouterMesConges);
				for (int i=0; i<8; i++)
					panBoutonHautMesConges.add(new JLabel("  "));
				panConges.removeAll();
				panConges.setUsrId(userConnecter.getUsrId());
				panConges.initComponents();
				monCompte.add(panBoutonHautMesConges, BorderLayout.CENTER);
				monCompte.add(panConges, BorderLayout.SOUTH);
				monCompte.revalidate();
				getContentPane().revalidate();
			}
	   });
		
	   boutonAnnulerAddConges.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				panelBoutonsAddConge.setVisible(false);
				panAddConges.setVisible(false);
				monCompte.remove(panelBoutonsAddConge);
				monCompte.remove(panAddConges);
				
				panBoutonHautMesConges.removeAll();
				panBoutonHautMesConges.setLayout(new GridLayout(1,10));
				panBoutonHautMesConges.add(boutonRetourMesConges);
				panBoutonHautMesConges.add(boutonAjouterMesConges);
				for (int i=0; i<8; i++)
					panBoutonHautMesConges.add(new JLabel("  "));
				panConges.removeAll();
				panConges.setUsrId(userConnecter.getUsrId());
				panConges.initComponents();
				monCompte.add(panBoutonHautMesConges, BorderLayout.CENTER);
				monCompte.add(panConges, BorderLayout.SOUTH);
				monCompte.revalidate();
				getContentPane().revalidate();
			}
	   });
	   
	   boutonValiderAddConges= new JButton("Valider");
	   boutonValiderAddConges.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				
				CongesMetier congeMetier= new CongesMetier();
				NombreJourCongesMetier nbrJrCon= new NombreJourCongesMetier();
				userConnecter = userMetier.findUserByLogin(getLogrecuperer());
				
				if ((panAddConges.getCalendarDateDeb().getDate()==null) || (panAddConges.getCalendarDateFin().getDate()==null))
					JOptionPane.showMessageDialog(null, "Veuillez saisir correctement les dates !");
				else	
					if (nbrJrCon.nombreJrCngRest(userConnecter.getUsrId()) < congeMetier.nbrejr(panAddConges.getCalendarDateDeb().getDate(),
							panAddConges.getCalendarDateFin().getDate()))
						JOptionPane.showMessageDialog(null, "Vous ne disposez pas assez de jours !");
					else
				   if ((panAddConges.getjTextArea1().getText().length()<2)||(congeMetier.nbrejr(panAddConges.getCalendarDateDeb().getDate(),
						panAddConges.getCalendarDateFin().getDate())<1))
					JOptionPane.showMessageDialog(null, "Veuillez remplir correctement les champs !");
				else{
					
					congeMetier.addCongesMetier(panAddConges.getCalendarDateDeb().getDate(), panAddConges.getCalendarDateFin().getDate(),
							panAddConges.getjTextArea1().getText(),nbrJrCon.nombreJrCngRest(userConnecter.getUsrId())-congeMetier.nbrejr(panAddConges.getCalendarDateDeb().getDate(),
									panAddConges.getCalendarDateFin().getDate()),userConnecter);
					nbrJrCon.modifierNbrJrCng(userConnecter.getUsrId(), congeMetier.nbrejr(panAddConges.getCalendarDateDeb().getDate(),
							panAddConges.getCalendarDateFin().getDate()));
				
				panelBoutonsAddConge.setVisible(false);
				panAddConges.setVisible(false);
				monCompte.remove(panelBoutonsAddConge);
				monCompte.remove(panAddConges);
	            
				panConges.removeAll();
				panBoutonHautMesConges.removeAll();
				panBoutonHautMesConges.setLayout(new GridLayout(1,10));
				panBoutonHautMesConges.add(boutonRetourMesConges);
				panBoutonHautMesConges.add(boutonAjouterMesConges);
				for (int i=0; i<8; i++)
					panBoutonHautMesConges.add(new JLabel("  "));
				
				panConges.setUsrId(userConnecter.getUsrId());
				panConges.initComponents();
				monCompte.add(panConges, BorderLayout.SOUTH);
				monCompte.add(panBoutonHautMesConges, BorderLayout.CENTER);
				getContentPane().validate();
			}
			}
		});

		panGaucheFenMain.setLayout(new GridLayout(10, 1));
		contenu.add(panCentreFenMain, BorderLayout.CENTER);
		contenu.add(panBasFenMain, BorderLayout.SOUTH);
		contenu.add(panGaucheFenMain, BorderLayout.WEST);
		// contenu.add(panHautFenMain, BorderLayout.NORTH);
		jLabel1 = new JLabel();
		labelBienVenue = new JLabel();
		labelBienVenue.setForeground(new java.awt.Color(255, 255, 255));
		labelConnecter = new JLabel(" ");

		labelConnecter.setForeground(new java.awt.Color(255, 255, 255));

		labelConnecter.setFont(new java.awt.Font("Verdana", 3, 14));

		buttonQuitter = new JButton();
		buttonMonCompte = new JButton();
		buttonGestionProjets = new JButton();
		boutonDeconnecter = new JButton();
		boutonUtilisateur = new JButton();
		boutonConge = new JButton();
		boutonAo = new JButton();
		boutonEntrees = new JButton();
		boutonSorties = new JButton();
		buttonAceuil = new JButton();
		boutonProspect = new JButton();
		labelProfil = new JLabel();
		labelProfil.setIcon(new javax.swing.ImageIcon(
				"src/main/java/com/photos/profil1.gif")); // NOI18N
		labelProfil.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1,
				1, 1, new java.awt.Color(191, 36, 94)));

		boutonCra = new JButton();
		jLabel2 = new JLabel();
		jPanel1 = new JPanel();
		jLabel4 = new JLabel();
		labelAcceuil = new JLabel();

		panHautFenMain.setBackground(new java.awt.Color(88, 89, 91));
		panHautFenMain.setBorder(javax.swing.BorderFactory
				.createLineBorder(new java.awt.Color(191, 36, 94)));

		panHautFenMain.setLayout(new BorderLayout());
		panHautFenMain.add(panHautFenMainGauche, BorderLayout.WEST);
		panHautFenMain.add(panHautFenMainCentre, BorderLayout.CENTER);
		panHautFenMainGauche.add(jLabel4, BorderLayout.WEST);
		panHautFenMain.add(panHautFenMainDroite, BorderLayout.EAST);
		// labelBienVenue.setFont(new java.awt.Font("Verdana", 3, 16));
		labelBienVenue.setBorder(null);
		labelBienVenue.setFont(new Font("Arial", Font.ITALIC, 25));// NOI18N
		labelBienVenue.setText(" ");
		panHautFenMainCentre.add(labelBienVenue, BorderLayout.CENTER);

		// setBackground(new java.awt.Color(255, 255, 255));
		contenu.add(panHautFenMain, BorderLayout.NORTH);
		panBasFenMain.setLayout(new BorderLayout());
		panHautFenMainCentre.setBackground(new java.awt.Color(88, 89, 91));
		panHautFenMainCentre
				.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1,
						1, new java.awt.Color(191, 36, 94)));
		panHautFenMainDroite.setBackground(new java.awt.Color(88, 89, 91));
		panHautFenMainDroite
				.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1,
						1, new java.awt.Color(191, 36, 94)));
		panHautFenMainDroite.add(labelProfil);
		panHautFenMainGauche.setBackground(new java.awt.Color(88, 89, 91));
		panHautFenMainGauche
				.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1,
						1, new java.awt.Color(191, 36, 94)));

		panBasFenMain.setBackground(new java.awt.Color(88, 89, 91));
		panBasFenMain.setBorder(javax.swing.BorderFactory.createMatteBorder(1,
				1, 1, 1, new java.awt.Color(191, 36, 94)));

		buttonQuitter = new BICButtonDegrade("Quitter");
		buttonQuitter.setBorder(javax.swing.BorderFactory.createMatteBorder(1,
				1, 1, 1, new java.awt.Color(191, 36, 94)));
		boutonDeconnecter = new BICButtonDegrade("Deconnecter");
		boutonDeconnecter
				.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1,
						1, new java.awt.Color(191, 36, 94)));
		buttonQuitter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				if (JOptionPane.showConfirmDialog(getFrame(),
						"Voulez-vous vraiment quitter ?", "Information",
						JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
					System.exit(0);
				}

			}
		});
		
		buttonValiderModifierMonCompte.addActionListener(new ActionListener(){
                                                        
			public void actionPerformed(ActionEvent arg0) {         
				// TODO Auto-generated method stub                
				UsersMetier usrmetier= new UsersMetier();  
			if ((monCompte.getTextAncienPassword().getText().equals(pass))&&(monCompte.getTextNewPassword().getText().equals(newPass))){
			if	(usrmetier.modifierCompte(logrecuperer, monCompte.getTextPhone().getText(), monCompte.getTextAdresse().getText(),
						monCompte.getTextAncienPassword().getText(), monCompte.getTextNewPassword().getText())){
				JOptionPane.showMessageDialog(null, "succès !");
				buttonValiderModifierMonCompte.setVisible(false);
				monCompte.getBoutonModifer().setVisible(true);
			}
			else                                                
				JOptionPane.showMessageDialog(null, "erreur !");
			}
			else{
				usrmetier.modifierCompteSansPassword(logrecuperer, monCompte.getTextPhone().getText(), monCompte.getTextAdresse().getText());
			}
			}
		});                                                                    
		                                                                        
	buttonMonCompte = new BICButtonDegrade("    Mon Compte");                             
		buttonMonCompte.setBorder(javax.swing.BorderFactory.createMatteBorder(                   
				1, 1, 1, 1, new java.awt.Color(191, 36, 94)));                      
		buttonMonCompte.addActionListener(new ActionListener() {                 
 
			public void actionPerformed(ActionEvent arg0) {                      
				// TODO Auto-generated method stub
				                                                                            
				monCompte.removeAll();
				monCompte.initComponents(boutonMesProjets,boutonMesConges,buttonValiderModifierMonCompte);
				monCompte.getLabelProfil().setIcon(
						new javax.swing.ImageIcon(
								"src/main/java/com/photos/user/"
										+ getLogrecuperer() + ".jpg"));
				String logMonCompte = getLogrecuperer();
				System.out.println("login recuperer corespondant au user connescté  "+ logMonCompte);
				userConnecter = userMetier.findUserByLogin(logMonCompte);                                       
				String nom = userConnecter.getUsrNom();
				String prenom = userConnecter.getUsrPrenom();
				String profil = userConnecter.getUsrProfil();
				String login = userConnecter.getUsrLogin();
				String passAncien = userConnecter.getUsrPasswd();
				// String passNouveau = userConnecter.getUsrPasswd();
				String email = userConnecter.getUsrEmail();
				String phone = userConnecter.getUsrPhone();
				String adresse = userConnecter.getUsrAdresse();
				// on remplit les champs dans monCompte

				pass=monCompte.getTextAncienPassword().getText();
				newPass=monCompte.getTextNewPassword().getText();
				monCompte.getTextPrenom().setText(prenom);
				monCompte.getTextNom().setText(nom);
				monCompte.getTextAdresse().setText(adresse);
				monCompte.getTextEmail().setText(email);
				monCompte.getTextLogin().setText(login);
				monCompte.getTextPhone().setText(phone);
				monCompte.getTextProfil().setText(profil);

				monCompte.getTextNom().setEditable(false);
				monCompte.getTextPrenom().setEditable(false);
				monCompte.getTextProfil().setEditable(false);
				monCompte.getTextAdresse().setEditable(false);
				monCompte.getTextLogin().setEditable(false);
				monCompte.getTextEmail().setEditable(false);
				monCompte.getTextPhone().setEditable(false);
				monCompte.getTextNewPassword().setVisible(false);
				monCompte.getjLabel9().setVisible(false);
				monCompte.getjLabel8().setVisible(false);
				monCompte.getTextAncienPassword().setVisible(false);
				//monCompte.getBoutonValider().setVisible(false);
				monCompte.getBoutonAnnuler().setVisible(false);

				panCentreFenMain.removeAll();
				panCentreFenMain.add(monCompte, BorderLayout.CENTER);
				panCentreFenMain.revalidate();
				getContentPane().revalidate();// on valide les changements

			}
		});

		panBasFenMain.add(buttonQuitter, BorderLayout.BEFORE_LINE_BEGINS);
		panBasFenMain.add(boutonDeconnecter, BorderLayout.AFTER_LINE_ENDS);
		panBasFenMain.add(labelConnecter, BorderLayout.CENTER);

		panGaucheFenMain.setBackground(new java.awt.Color(128, 130, 133));
		panGaucheFenMain.setBorder(javax.swing.BorderFactory.createMatteBorder(
				1, 1, 1, 1, new java.awt.Color(191, 36, 94)));

		buttonGestionProjets = new BICButtonDegrade("PROJETS");
		boutonProspect.setBackground(new java.awt.Color(191, 36, 94));

		boutonProspect = new BICButtonDegrade("PROSPECTS");
		boutonProspect.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub

				panCentreFenMain.removeAll();
				PanelProspects panProspect = new PanelProspects();
				panCentreFenMain.add(panProspect, BorderLayout.CENTER);
				getContentPane().validate();

			}
		});

	
		boutonCra = new BICButtonDegrade("Compte Rendu");
		boutonCra.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				panCentreFenMain.removeAll();
				userConnecter = userMetier.findUserByLogin(getLogrecuperer());
				// usrrecup = userConnecter.getUsrId() ;
				System.out
				.println("iduserrecuperer corespondant au user connescté  "
						+ userConnecter.getUsrId());
				PanelCompteRendu  panCompteRendu = new PanelCompteRendu();
				   panCompteRendu.setUsrid(userConnecter.getUsrId());
				 panCompteRendu.initComponents();
			 	panCentreFenMain.add(panCompteRendu, BorderLayout.CENTER);
				getContentPane().validate();
			}
		});
		buttonGestionProjets.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				panCentreFenMain.removeAll();
				fenGestionConsultant.removeAll();
				fenGestionConsultant.initComponents(boutonRechercher);
				fenGestionConsultant.revalidate();
				panCentreFenMain.add(fenGestionConsultant, BorderLayout.CENTER);
				getContentPane().validate();

			}
		});
		boutonRechercher.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				panelRechercheProjet.setSize(1050, 450);
				javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
		        JTable tableProjet = new javax.swing.JTable();
		        String logMonCompte = getLogrecuperer();
				System.out.println("login recuperer corespondant au user connescté  "+ logMonCompte);
				userConnecter = userMetier.findUserByLogin(logMonCompte);     
		        
		        ProjetMetier projetsMetier= new ProjetMetier();
		        List<Projets> mesProjets=projetsMetier.projetsChercher(fenGestionConsultant.getDateDebutProjet().getDate(),
		        		fenGestionConsultant.getDateFinProjet().getDate());
		        if (mesProjets != null){
		        int nombreLigne = mesProjets.size();
		 		Object data[][] = new Object[nombreLigne][4];

		 		for (int i = 0; i < nombreLigne; i++) {
		 			Projets cng=mesProjets.get(i);
		 		data[i][0]= cng.getProjetNum();
		 		data[i][1]= cng.getProjetRef();
		 		data[i][2]= cng.getProjetEtat();
		 		data[i][3]= cng.getProjetDesc();
		 		}

		        tableProjet.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
		        tableProjet.setModel(new javax.swing.table.DefaultTableModel(data,
		            new String [] {
		                "Numéro", "Référence", "Etat", "Description"
		            }
		        ));
		        
		        jScrollPane1.setViewportView(tableProjet);
		        panelRechercheProjet.add(jScrollPane1);
		        }
		        else
		        	panelRechercheProjet.add(new JLabel("Aucun résultat ne correspond à votre recherche !"));
		        fenGestionConsultant.remove(fenGestionConsultant.getPanelbas());
		        fenGestionConsultant.add(panelRechercheProjet, BorderLayout.SOUTH);
		        getContentPane().revalidate();    
			}
		});

		boutonUtilisateur = new BICButtonDegrade("UTILISATEURS");
		boutonUtilisateur.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				panCentreFenMain.removeAll();
				PanelConsultant panUser = new PanelConsultant();
				panCentreFenMain.add(panUser, BorderLayout.CENTER);
				getContentPane().validate();

			}
		});

		        
		boutonConge = new BICButtonDegrade("CONGES");
                 
		boutonAo = new BICButtonDegrade("A.O");
		boutonAo.addActionListener(new ActionListener() {
                   
			public void actionPerformed(ActionEvent e) {
				
				panCentreFenMain.removeAll();
				PanelAppelDoffre panAo = new PanelAppelDoffre();
				panCentreFenMain.add(panAo, BorderLayout.CENTER);
				getContentPane().validate();
                
			}   
		});     
                
		// boutonEntrees.setBackground(new java.awt.Color(191, 36, 94));
		// boutonEntrees.setFont(new java.awt.Font("Verdana", 3, 14));
		// boutonEntrees.setText("ENTREES");
		boutonEntrees = new BICButtonDegrade("ENTREES");
		boutonEntrees.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				panCentreFenMain.removeAll();
				PanEntres pan = new PanEntres();
				// PanelSorties pan=new PanelSorties();
				panCentreFenMain.add(pan, BorderLayout.CENTER);
				getContentPane().validate();

			}
		});
		
		boutonSorties = new BICButtonDegrade("SORTIES");
		boutonSorties.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				panCentreFenMain.removeAll();
				PanelSorties pan = new PanelSorties();
				panCentreFenMain.add(pan, BorderLayout.CENTER);
				getContentPane().validate();

			}
		});

		buttonAceuil = new BICButtonDegrade("ACCEUIL");
		buttonAceuil.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				panCentreFenMain.removeAll();
				FenMain fenMain = new FenMain();
				panCentreFenMain.add(fenMain.panCentreFenMain);
				getContentPane().validate();

			}
		});
		boutonDeconnecter.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if (JOptionPane.showConfirmDialog(getFrame(),
						"Voulez-vous vraiment Deconnecter ?", "Information",
						JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
					FenLogin fenLogin = new FenLogin();
					fenLogin.setVisible(true);
					dispose();
				}

			}
		});

		panGaucheFenMain.add(buttonAceuil);
		panGaucheFenMain.add(boutonUtilisateur);
		panGaucheFenMain.add(buttonGestionProjets);
		// panGaucheFenMain.add(boutonConge);
		 panGaucheFenMain.add(boutonCra);
		panGaucheFenMain.add(boutonAo);
		panGaucheFenMain.add(boutonProspect);
		panGaucheFenMain.add(boutonEntrees);
		panGaucheFenMain.add(boutonSorties);
		panGaucheFenMain.add(buttonMonCompte);

		panCentreFenMain.setBackground(new java.awt.Color(128, 130, 133));
		panCentreFenMain.setBorder(javax.swing.BorderFactory.createMatteBorder(
				1, 1, 1, 1, new java.awt.Color(191, 36, 94)));

		jLabel2.setBackground(new java.awt.Color(223, 242, 255));
		jLabel2.setIcon(new javax.swing.ImageIcon(
				"src/main/java/com/photos/Acceuil Idyal finish new.jpg")); // NOI18N
		jLabel2.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1,
				1, new java.awt.Color(191, 36, 94)));
		panCentreFenMain.add(jLabel2, BorderLayout.CENTER);

		jPanel1.setBackground(new java.awt.Color(128, 130, 133));
		jPanel1.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1,
				1, new java.awt.Color(191, 36, 94)));

		jLabel4.setIcon(new javax.swing.ImageIcon(
				"src/main/java/com/photos/New Logo Groupe IDyalFenMain.jpg")); // NOI18N
		jLabel4.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1,
				1, new java.awt.Color(191, 36, 94)));

		pack();
	}

	public JFrame getFrame() {
		return this;
	}

	public JLabel getLabelBienVenue() {
		return labelBienVenue;
	}

	public void setLabelBienVenue(JLabel labelBienVenue) {
		this.labelBienVenue = labelBienVenue;
	}

	public JPanel getPanHautFenMainCentre() {
		return panHautFenMainCentre;
	}

	public void setPanHautFenMainCentre(JPanel panHautFenMainCentre) {
		this.panHautFenMainCentre = panHautFenMainCentre;
	}

	public JPanel getPanBasFenMain() {
		return panBasFenMain;
	}

	public void setPanBasFenMain(JPanel panBasFenMain) {
		this.panBasFenMain = panBasFenMain;
	}

	public JButton getButtonAceuil() {
		return buttonAceuil;
	}

	public void setButtonAceuil(JButton buttonAceuil) {
		this.buttonAceuil = buttonAceuil;
	}

	public JButton getBoutonCra() {
		return boutonCra;
	}

	public void setBoutonCra(JButton boutonCra) {
		this.boutonCra = boutonCra;
	}

	public JPanel getPanGaucheFenMain() {
		return panGaucheFenMain;
	}

	public void setPanGaucheFenMain(JPanel panGaucheFenMain) {
		this.panGaucheFenMain = panGaucheFenMain;
	}

	public JButton getBoutonProspect() {
		return boutonProspect;
	}

	public void setBoutonProspect(JButton boutonProspect) {
		this.boutonProspect = boutonProspect;
	}

	public JButton getBoutonUtilisateur() {
		return boutonUtilisateur;
	}

	public void setBoutonUtilisateur(JButton boutonUtilisateur) {
		this.boutonUtilisateur = boutonUtilisateur;
	}

	public JButton getBoutonConge() {
		return boutonConge;
	}

	public void setBoutonConge(JButton boutonConge) {
		this.boutonConge = boutonConge;
	}

	public JButton getBoutonAo() {
		return boutonAo;
	}

	public void setBoutonAo(JButton boutonAo) {
		this.boutonAo = boutonAo;
	}

	public JButton getBoutonEntrees() {
		return boutonEntrees;
	}

	public void setBoutonEntrees(JButton boutonEntrees) {
		this.boutonEntrees = boutonEntrees;
	}

	public JButton getBoutonSorties() {
		return boutonSorties;
	}

	public void setBoutonSorties(JButton boutonSorties) {
		this.boutonSorties = boutonSorties;
	}

	public JLabel getLabelProfil() {
		return labelProfil;
	}

	public void setLabelProfil(JLabel labelProfil) {
		this.labelProfil = labelProfil;
	}

	public JPanel getPanHautFenMainDroite() {
		return panHautFenMainDroite;
	}

	public void setPanHautFenMainDroite(JPanel panHautFenMainDroite) {
		this.panHautFenMainDroite = panHautFenMainDroite;
	}

	public JButton getButtonMonCompte() {
		return buttonMonCompte;
	}

	public void setButtonMonCompte(JButton buttonMonCompte) {
		this.buttonMonCompte = buttonMonCompte;
	}

	// la méthode qui permet au défilement du labelBienVenue
	public void go() {
		long temps = 500;
		long startTime = 0;
		Timer timer = new Timer();
		TimerTask tache = new TimerTask() {
			public void run() {
				char chr = ' ';
				String text = null;
				chr = labelBienVenue.getText().charAt(0);
				text = labelBienVenue.getText().substring(1);
				text += chr;
				labelBienVenue.setText(text);
			}
		};
		timer.scheduleAtFixedRate(tache, startTime, temps);
	}

	// la méthode qui permet au défilement du labelBienVenue
	public void defiler() {
		long temps = 500;
		long startTime = 0;
		Timer timer = new Timer();
		TimerTask tache = new TimerTask() {
			public void run() {
				char chr = ' ';
				String text = null;
				chr = labelConnecter.getText().charAt(0);
				text = labelConnecter.getText().substring(1);
				text += chr;
				labelConnecter.setText(text);
			}
		};
		timer.scheduleAtFixedRate(tache, startTime, temps);
	}

	public static void main(String[] args) {
		FenMain fenMain = new FenMain();
		fenMain.setVisible(true);
	}

	private boolean comparaison(String chaine1, String chaine2) {
		boolean ok = false;
		if (chaine1.equals(chaine2))
			ok = true;
		else {
			if (chaine1.length() == chaine2.length())
				ok = false;
			else {
				int i = 0;
				if (chaine1.length() < chaine2.length()) {
					while (!(ok) && (i < chaine1.length())) {
						ok = chaine1.charAt(i) == chaine2.charAt(i);
						i++;
					}
					if (i == chaine1.length())
						while (!(ok) && (i < chaine2.length())) {
							ok = chaine2.charAt(i) == ' ';
							i++;
						}
				}
				if (chaine1.length() > chaine2.length()) {
					while (!(ok) && (i < chaine2.length())) {
						ok = chaine2.charAt(i) == chaine1.charAt(i);
						i++;
					}
					if (i == chaine2.length())
						while (!(ok) && (i < chaine1.length())) {
							ok = chaine1.charAt(i) == ' ';
							i++;
						}
				}
			}
		}
		return ok;
	}
}
